package com.rockwell.robot2015.model.detectors;

import org.opencv.core.Point;

import com.rockwell.robot2015.model.ColorBlobInfo;
import com.rockwell.robot2015.model.OnColorBlobDetectListener;

public class DropAreaDetector extends ObjectDetector {
	private static int MIN_SIZE;
	
	public DropAreaDetector(OnColorBlobDetectListener listener) {
		super(listener);
	}
	
	@Override
	public void onDetect(boolean present, ColorBlobInfo info, int height, int width) {
		if (present && info.center.y < height * FOV_HEIGHT_BOUNDARY)
			present = false;
		
		if (present && info.center.y > height * (1 - FOV_HEIGHT_BOUNDARY))
			present = false;

		MIN_SIZE = Math.min(height, width) / 3;
		
		if (info.radius < MIN_SIZE) {
			present = false;
			return;
		}

		/*
		MIN_SIZE = Math.min(height, width) / 3;
		
		if (info.boundingRect != null && info.boundingRect.width < MIN_SIZE && info.boundingRect.height < MIN_SIZE) {
			m_present = false;
			return;
		}
		
		if (info.radius < MIN_SIZE) {
			present = false;
			return;
		}
		*/
		
		if (!this.m_present && !present)
			return;
		
		if (this.m_present && present)
		{
			double difX = Math.abs(m_center.x - info.center.x);
			double difY = Math.abs(m_center.y - info.center.y);
			
			if (difX < 1 && difY < 1)
				return;
		}
		
		m_present = present;
		m_center = info.center;
		m_radius = info.radius;
		m_boundingRect = info.boundingRect;

		if (m_width != width)
			m_width = width;
		
		if (m_height != height)
			m_height = height;
	}
}
